#!/bin/bash

TEST_CNF=./test_cnf.sh
SOLVE_ALL=./solve_all.sh

#$SOLVE_ALL >&2 2> /dev/null

FAILED=0
SUCCESS=0
ERROR=0
TOTAL=0
THREADS="1 5"

for thread in $THREADS
do

	for cnf in *.cnf
	do

		if ! [[ $cnf =~ "_without_unary.cnf" ]]
		then

			echo "Testing file: $cnf with $thread threads"
			PREFIX=`echo $cnf | sed s/".cnf"//g`
			$TEST_CNF $PREFIX $thread

			RETURN=$?

			if [[ "$RETURN" == "1" ]] || [[ "$RETURN" == "2" ]]
			then
				echo -e '\e[33;1mSomething wrong has happened.\e[m'
				let ERROR++
			fi

			if [[ "$RETURN" == "10" ]]
			then
				echo -e '\e[32;1mSolutions MATCH\e[m'
				let SUCCESS++
			fi

			if [[ "$RETURN" == "20" ]]
	        	then
        	        	echo -e '\e[31;1mSolutions DO NOT MATCH\e[m'
				let FAILED++
		        fi

			let TOTAL++
		fi
	done

done

echo
echo "Summary:"

if [[ "$SUCCESS" == "$TOTAL" ]]
then

	echo -e "\e[32;1mAll $TOTAL files matched!\e[m"

else

	echo -e "\e[31;1mThere were $ERROR errors and $FAILED mismatches of $TOTAL\e[m"

fi


